package smallTools_testCase;
import smallTools.SimpleTime;
import junit.framework.TestCase;

public class SimpleTimeTest extends TestCase{

	// Test case 0: SimpleTime() and toString()
	public void testDefaultConstructor_and_toString() {
		SimpleTime st=new SimpleTime();
		String result = st.toString();
		assertEquals("Sun 00:00",result);
	}

	// Test case 1: test wrong input
	public void testWrongInput() {
		SimpleTime st=new SimpleTime("ABC",10,20);
		assertEquals(0,st.getDay());
		st=new SimpleTime("Mon",25,10);		
		assertEquals("Mon 01:10",st.toString());		
		st=new SimpleTime("Mon",25,61);		
		assertEquals("Mon 01:01",st.toString());
		st=new SimpleTime("Mon",3,1501);		
		assertEquals("Mon 03:01",st.toString());		
	}
	
	// Test case 1: SimpleTime(String day,int hour,int minute) and toInt()
	public void testConstructor_and_toInt() {
		SimpleTime st=new SimpleTime("Mon",0,10);
		int result = st.toInt();
		assertEquals(10010,result);
	}
	
	// Test case 2: getEndTime(int duration) and SimpleTime(SimpleTime rhs)
	public void testCopyConstructor_and_getEndTime()
	{
		SimpleTime str=new SimpleTime("Mon",10,20);
		SimpleTime end=str.getEndTime(3);
		assertEquals("Mon 10:20",str.toString());
		assertEquals("Mon 13:20",end.toString());
		
		str=new SimpleTime("Sat",22,10);
		end=str.getEndTime(3);
		assertEquals("Sat 22:10",str.toString());
		assertEquals("Sun 01:10",end.toString());		
	}
	
	// Test case 3: getDay() getHour() and getMinute()
	public void testGetters()
	{
		SimpleTime st=new SimpleTime("Tue",3,20);
		assertEquals(2,st.getDay());
		assertEquals(3,st.getHour());
		assertEquals(20,st.getMinute());
	}
	
	// Test case 4: testing all statements in dayStringToInt()
	public void test_dayStringToInt()
	{
		assertEquals(0,SimpleTime.dayStringToInt("Sun"));
		assertEquals(1,SimpleTime.dayStringToInt("Mon"));
		assertEquals(2,SimpleTime.dayStringToInt("Tue"));
		assertEquals(3,SimpleTime.dayStringToInt("Wed"));
		assertEquals(4,SimpleTime.dayStringToInt("Thu"));
		assertEquals(5,SimpleTime.dayStringToInt("Fri"));
		assertEquals(6,SimpleTime.dayStringToInt("Sat"));
		assertEquals(0,SimpleTime.dayStringToInt("AAA"));
	}
	
	// Test case 5: testing all statements in dayIntToString()
	public void test_dayIntToString()
	{
		assertEquals("Sun",SimpleTime.dayIntToString(0));
		assertEquals("Mon",SimpleTime.dayIntToString(1));
		assertEquals("Tue",SimpleTime.dayIntToString(2));
		assertEquals("Wed",SimpleTime.dayIntToString(3));
		assertEquals("Thu",SimpleTime.dayIntToString(4));
		assertEquals("Fri",SimpleTime.dayIntToString(5));
		assertEquals("Sat",SimpleTime.dayIntToString(6));
		assertEquals("Sun",SimpleTime.dayIntToString(7));
	}
	
	// Test case 6: areSectionsConflicted()
	public void test_areSectionsConflicted()
	{
		SimpleTime start0=new SimpleTime("Mon",11,30);
		int duration0=2;
		
		SimpleTime st1=new SimpleTime("Mon",10,30);
		assertEquals(false,SimpleTime.areSectionsConflicted(start0, duration0, st1, 1));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st1, 2));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st1, 3));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st1, 4));
		
		SimpleTime st2=new SimpleTime("Mon",11,30);
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st2, 1));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st2, 2));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st2, 3));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st2, 4));
		
		SimpleTime st3=new SimpleTime("Mon",12,30);
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st3, 1));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st3, 2));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st3, 3));
		assertEquals(true,SimpleTime.areSectionsConflicted(start0, duration0, st3, 4));
		
		SimpleTime st4=new SimpleTime("Mon",13,30);
		assertEquals(false,SimpleTime.areSectionsConflicted(start0, duration0, st4, 1));
		assertEquals(false,SimpleTime.areSectionsConflicted(start0, duration0, st4, 2));
		assertEquals(false,SimpleTime.areSectionsConflicted(start0, duration0, st4, 3));
		assertEquals(false,SimpleTime.areSectionsConflicted(start0, duration0, st4, 4));
	}
}
